import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:saas_order_meal/net/net_response/order_detail_data.dart';
import 'package:saas_order_meal/ui/has_order_detail_content.dart';

import '../saas_order_meal.dart';

class HasOrderedMealPage extends StatefulWidget {
  List<HasOrderData> hasOrderMealList;
  String date;

  HasOrderedMealPage({required this.hasOrderMealList, required this.date});

  @override
  State<StatefulWidget> createState() => _HasOrderedMealState();
}

Future<dynamic> showDetail(BuildContext context,
    {required List<HasOrderData> hasOrderMealList,
    required String date}) async {
  return await showModalBottomSheet(
      context: context,
      constraints: BoxConstraints(
          minHeight: MediaQuery.of(context).size.height * 0.7,
          maxHeight: MediaQuery.of(context).size.height * 0.8),
      builder: (context) {
        return HasOrderedMealPage(
            hasOrderMealList: hasOrderMealList, date: date);
      },
      enableDrag: false,
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      isDismissible: true);
}

class _HasOrderedMealState extends State<HasOrderedMealPage> {
  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: DefaultTabController(
        length: widget.hasOrderMealList.length,
        child: Column(
          children: [
            Stack(
              alignment: Alignment.center,
              children: [
                Container(width: MediaQuery.of(context).size.width,height: 10,),
                Text(
                  '${widget.date}已点',
                  style: TextStyle(fontSize: 16, color: Colors.blue),
                ),

                Icon(Icons.close).onTap(() {
                  Go().pop();
                }).setLocation(left: 16)
              ],
            ).addToContainer(height: 50),
            TabBar(
                labelColor: SaasOrderMeal.mainColor,
                unselectedLabelColor: Colors.grey,
                indicatorSize: TabBarIndicatorSize.label,
                labelStyle:
                    TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                unselectedLabelStyle:
                    TextStyle(fontSize: 16, fontWeight: FontWeight.normal),
                tabs: widget.hasOrderMealList
                    .map((e) => Tab(
                          text: e.name,
                        ))
                    .toList()),
            TabBarView(
                    children: widget.hasOrderMealList
                        .map((e) => HasOrderDetailContent(
                              detail: e.detail!,
                            ))
                        .toList())
                .setWeight(1)
          ],
        ),
      ),
    ).addToContainer(
      height: MediaQuery.of(context).size.height * 0.7,
      decoration:
          BoxDecoration(color: Colors.white, borderRadius: 20.borderRadius),
      padding: EdgeInsets.only(top: 10),
    );
  }
}

class HasOrderData {
  String name;
  OrderDetailData? detail;

  HasOrderData({required this.name, required this.detail});
}
